package org.urchr.beorganized.api.impl.permission;

import org.urchr.beorganized.api.base.PrivateBaseAPIServlet;
import org.urchr.beorganized.dao.NotesDAO;
import org.urchr.beorganized.dao.PermissionsDAO;
import org.urchr.beorganized.dao.XMLDocumentBuilder;
import org.urchr.beorganized.dao.errors.GeneralException;

public class AddPermission extends PrivateBaseAPIServlet {

	@Override
	protected void doProcessPrivate() throws GeneralException {
		int noteID = NotesDAO.safeInt(request.getParameter("noteid"), -1);
		String login = request.getParameter("user");
		boolean allowCreate = "true".equals(request.getParameter("is_create"));
		boolean allowEdit = "true".equals(request.getParameter("is_edit"));
		boolean allowDelete = "true".equals(request.getParameter("is_delete"));
		
		PermissionsDAO.addPermission(userID, noteID, login, allowCreate, allowEdit, allowDelete);
		XMLDocumentBuilder doc = new XMLDocumentBuilder();
		sendNode(doc.getRootElement("ok"));
	}

}
